package com.glela.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.glela.common.constant.BaseRestrictionsEnum;
import com.glela.platform.model.BaseRestrictions;
import com.glela.platform.service.BaseRestrictionsService;

/**
 * 系统控制类
 * @author zls
 *
 */
@Controller
@RequestMapping(value = "sys", produces = "application/json;charset=UTF-8")
public class SysController extends BaseController {
	@Autowired
	private BaseRestrictionsService baseRestrictionsService;

	/**
	 * <dl>
	 * <dt>系统公告</dt>
	 * </dl>
	 * @return ResponseEntity<?>
	 * @author zls
	 * @date 2017年9月18日 下午2:16:10
	 */
	@RequestMapping(value = "announcement")
	public @ResponseBody String get_sys_announcement(Boolean refresh) {
		String rslt = null;
		if (refresh == null || !refresh) {
			rslt = queryCacheResult();
		}
		if (rslt != null) {
			return rslt;
		}

		Map<Object, Object> hashMap = new HashMap<>();
		hashMap.put("hasNotice", false);
		try {
			BaseRestrictions baseRestrictionsForCache = baseRestrictionsService.getBaseRestrictionsForCache(BaseRestrictionsEnum.SYS_ANNOUNCEMENT);
			if (baseRestrictionsForCache != null && baseRestrictionsForCache.getRestrictions() == 1 && baseRestrictionsForCache.getStatus() == 1) {
				hashMap.put("content", baseRestrictionsForCache.getName());
				hashMap.put("hasNotice", true);
			}
			hashMap.put("title", "公告");
			//			//设置图片
			//			Map<Object, Object> iconMap = new HashMap<>();
			//			hashMap.put("icon", iconMap);
			//			iconMap.put("small", StringUtils.EMPTY);
			//			iconMap.put("large", StringUtils.EMPTY);
		} catch (Exception e) {
			getLOGGER().error("获取系统公告信息失败：{}", e.getMessage(), e);
		}
		return toCacheResult(toResultModelJSON(hashMap));
	}
}